package com.gimi.cloud.jimi.manage.consumer.service.sys.impl;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.exception.MsgException;
import com.gimi.cloud.jimi.common.utils.EntityVerification;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.common.utils.reqhead.Verification;
import com.gimi.cloud.jimi.dto.params.AuthListParams;
import com.gimi.cloud.jimi.dto.params.DoAuthParams;
import com.gimi.cloud.jimi.dto.sys.SysAuthorityDTO;
import com.gimi.cloud.jimi.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.jimi.manage.consumer.service.sys.AuthService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by shazhiwei on 2017/12/18.
 */
@Service
public class AuthSreviceImpl implements AuthService {
    private final SystemFeignService authFeignService;
    private static Logger logger = LoggerFactory.getLogger(MasterServiceImpl.class);

    public AuthSreviceImpl(SystemFeignService authFeignService){
        this.authFeignService = authFeignService;
    }

    @Override
    public Response authList(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        SysAuthorityDTO sysAuthorityDTO = JsonUtil.jsonToBean(requestBody,SysAuthorityDTO.class);
        if(null == sysAuthorityDTO.getRoId()){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"角色id为空，获取菜单列表失败");
        }
        return authFeignService.getAuthList(sysAuthorityDTO);
    }

    @Override
    public Response doAuth(String requestBody, HttpServletRequest request, HttpServletResponse response) throws MsgException {
        logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
        SysAuthorityDTO sysAuthorityDTO = JsonUtil.jsonToBean(requestBody,SysAuthorityDTO.class);
        if(null == sysAuthorityDTO.getRoId()){
            throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"角色id为空，授权失败");
        }
        return authFeignService.doAuth(sysAuthorityDTO);
    }

}
